home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows News 2010 Summer - Disc 1
/
WN_Ete2010_CD1.iso
/
Onglet5
/
Weezo
/
Weezo setup.exe
/
{code_appDir}
/
www
/
local
/
themeSelection.php
< prev
next >
Wrap
PHP Script
|
2010-05-19
|
18KB
|
459 lines
<?php
/**
* Theme selection interface
*
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category NA
* @package NA
* @author Nicolas Bruley / Peer 2 World <contact@weezo.net>
* @copyright 2005-2009 Nicolas Bruley / Peer 2 World
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
* @link http://www.weezo.net
* @since File available since Release 1.0.9
*/
if(!cfIsInApp()) die();
/**
* @desc echo async js script that update thumbnail position and src
*
* @param string $theme
*/
function themeSelectionThumbnailAsyncUpdate($theme=false){
if(!$theme) $theme=cfGGetVar('theme');
// Update $wallpaper && $wallpaperPosition
list($wallpaper,$wallpaperPosition)=themeSelectionGetWallpaper($theme);
echo cfAsyncXMLJSaction('setWallpaper("'.$theme.'","'.(($wallpaper)?$wallpaperPosition:'').'")');
}
/**
* @desc unlink all background images for selected theme
*
* @param string $theme
*/
function themeSelectionClearImages($theme=false){
if(!$theme) $theme=cfGGetVar('theme');
@unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-centered.jpg');
@unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-stretched.jpg');
@unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-tiled.jpg');
@unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-centered.gif');
@unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-stretched.gif');
@unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-tiled.gif');
@unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-centered.png');
@unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-stretched.png');
@unlink(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-tiled.png');
}
/**
* @desc Echo image of preview
*
*/
function themeSelectionPreviewThumbnail(){
WHeaders::noCache();
WHeaders::contentType('image/jpeg');
$wpTheme=cfGGetVar('theme');
list($wallpaper,$wallpaperPosition)=themeSelectionGetWallpaper();
cfCreateResizedJPG(cfAppDocRoot().$wallpaper,0,0,'',120,60);
exit;
}
/**
* Return array (wallpaper src (false if no wallpaper) / wallpaper position (centered/tiled/stretched) for a given theme
*
* @param string $theme
* @return array(string,string)
*/
function themeSelectionGetWallpaper($theme=false){
if(!$theme) $theme=cfGGetVar('theme');
$wallpaper=false;
$wallpaperPosition='centered';
if(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-centered.jpg')){$wallpaper='/themes/'.$theme.'/wallpaper-centered.jpg'; $wallpaperPosition='centered';}
elseif(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-stretched.jpg')){$wallpaper='/themes/'.$theme.'/wallpaper-stretched.jpg'; $wallpaperPosition='stretched';}
elseif(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-tiled.jpg')){$wallpaper='/themes/'.$theme.'/wallpaper-tiled.jpg'; $wallpaperPosition='tiled';}
if(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-centered.gif')){$wallpaper='/themes/'.$theme.'/wallpaper-centered.gif'; $wallpaperPosition='centered';}
elseif(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-stretched.gif')){$wallpaper='/themes/'.$theme.'/wallpaper-stretched.gif'; $wallpaperPosition='stretched';}
elseif(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-tiled.gif')){$wallpaper='/themes/'.$theme.'/wallpaper-tiled.gif'; $wallpaperPosition='tiled';}
if(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-centered.png')){$wallpaper='/themes/'.$theme.'/wallpaper-centered.png'; $wallpaperPosition='centered';}
elseif(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-stretched.png')){$wallpaper='/themes/'.$theme.'/wallpaper-stretched.png'; $wallpaperPosition='stretched';}
elseif(file_exists(cfAppDocRoot().'/themes/'.$theme.'/wallpaper-tiled.png')){$wallpaper='/themes/'.$theme.'/wallpaper-tiled.png'; $wallpaperPosition='tiled';}
return array($wallpaper,$wallpaperPosition);
}
/**
* Process POST commands
*
*/
function themeSelectionProcessCommands(){
global $themes;
global $wpTheme;
/*
* Wallpaper upload processing
*/
if(isset($_POST['position']) && isset($_FILES['wallpaperUpload'])) {
// new image sent
if(strlen($_FILES['wallpaperUpload']['name']) && !empty($_FILES['wallpaperUpload']['tmp_name']) && is_uploaded_file($_FILES['wallpaperUpload']['tmp_name'])){
// Check uploaded image format from name
if($_FILES['wallpaperUpload']['type']!='image/jpeg' && $_FILES['wallpaperUpload']['type']!='image/pjpeg' && $_FILES['wallpaperUpload']['type']!='image/gif' && $_FILES['wallpaperUpload']['type']!='image/png') die(cfAsyncFooter());
elseif($_POST['position']=='centered' || $_POST['position']=='stretched' || $_POST['position']=='tiled'){
$tmpFile=cfAppDocRoot().'/themes/'.$wpTheme.'/wallpaper-temp.'.cfFileExtension($_FILES['wallpaperUpload']['name']);
$destFile=cfAppDocRoot().'/themes/'.$wpTheme.'/wallpaper-'.$_POST['position'].'.'.((cfFileExtension($_FILES['wallpaperUpload']['name'])=='jpeg')?'jpg':cfFileExtension($_FILES['wallpaperUpload']['name']));
@unlink($tmpFile);
if(move_uploaded_file($_FILES['wallpaperUpload']['tmp_name'], $tmpFile)){
@unlink($destFile);
// Copy uploaded wallpaper
rename($tmpFile, $destFile);
}
}
}
// no new image
else{
// Change current wallpaper position
if($wallpaper && $_POST['position']=='centered' || $_POST['position']=='stretched' || $_POST['position']=='tiled'){
@rename(cfAppDocRoot().$wallpaper,cfAppDocRoot().'/themes/'.$wpTheme.'/wallpaper-'.$_POST['position'].'.'.cfFileExtension($wallpaper));
}
}
}
// Async commands
if(!cfIsAsync()) return;
echo cfAsyncHeader();
/**
* Change theme
*/
if(isset($_POST['setTheme']) && ($_POST['setTheme']=='no' || isset($themes[$_POST['setTheme']]))){
if($_POST['setTheme']=='-') $_POST['setTheme']='';
// General theme
if($_POST['userFile']=='' || $_POST['userFile']=='general'){
cfGUpdateVar('theme',$_POST['setTheme'],true);
// Update client-side thumbnail
themeSelectionThumbnailAsyncUpdate();
}
// User theme
elseif (WEnv::userConfigs($_POST['userFile'])){
$uc=new WUserConfig($_POST['userFile']);
if($uc->isValid()){
// Modify current user config
if(cfIsInApp()) $uc->setVar('theme',($_POST['setTheme']=='no')?'':$_POST['setTheme']);
// Single user account: commit to user configuration
if(cfIsInApp() || cfUGetVar('accountType')=='singleUser') $uc->save();
if(WEnv::user()) WEnv::user()->setVar('theme',$_POST['setTheme']);
// Logged user: reload desktop
//echo cfAsyncXMLJSaction('winMe.reloadDesktop()');
}
}
}
/**
* Change login type
*/
if(isset($_POST['loginForm'])){
if($_POST['loginForm']=='classic' || $_POST['loginForm']=='coverflow') cfGUpdateVar('loginForm',$_POST['loginForm'],true);
}
/**
* Change Wallpaper position
*/
if(isset($_POST['setPosition'])){
$pos=$_POST['setPosition'];
$wpTheme=cfGGetVar('theme');
list($wallpaper,$wallpaperPosition)=themeSelectionGetWallpaper();
$srcFile=cfAppDocRoot().$wallpaper;
if(is_file($srcFile) && ($pos==='centered' || $pos==='tiled' || $pos==='stretched')){
$destFile=dirname($srcFile).'/wallpaper-'.$pos.'.'.cfFileExtension($srcFile);
if($destFile!==$srcFile) @unlink($destFile);
@rename($srcFile,$destFile);
themeSelectionThumbnailAsyncUpdate();
}
elseif ($pos==='no') themeSelectionClearImages($wpTheme);
}
// Close window on double click
if(@$_POST['close']) echo cfAsyncJSaction('wl.UICommand(\'close:'.@$_POST['setTheme'].'\')');
die(cfAsyncFooter());
}
/**
* @desc Display login type selection form
*
*/
function themeSelectionLoginTypeSelection(){
echo outDivFrame('frame1');
echo '<div class="frame1Header">'.outImageIcon('lock').cfCaption('loginPage').'</div>';
echo outDivFrame('frame2','','text-align:center');
// Classic login
echo outBlockItem('loginForm',outImage(outIcon('loginFormClassic')),'ondblclick="selectLoginType(\'classic\',1)"','',array('onclick'=>'selectLoginType(\'classic\')'),(cfGGetVar('loginForm')!=='coverflow')?'sel':'unsel')."\n";
// Coverflow login
echo outBlockItem('loginForm',outImage(outIcon('loginFormCoverflow')),'ondblclick="selectLoginType(\'coverflow\',1)"','',array('onclick'=>'selectLoginType(\'coverflow\')'),(cfGGetVar('loginForm')==='coverflow')?'sel':'unsel');
?>
</div>
</div>
<br>
<br>
<?php
}
/**
* @desc Display wallpaper selection form
*
*/
function themeSelectionWallpaperSelection(){
global $wallpaper, $wallpaperPosition;
echo outDivFrame('frame1',false,'margin-top:10px');
echo '<div class="frame1Header">'.outImage(outIcon('wallpaper'),false,false,'margin-right:1em; vertical-align:middle').cfCaption('genWallpaper').'</div>';
// No image
echo outDivFrame('frame2');
echo '<input type="radio" id="noUse" name="useWallpaper" value="no"'.(($wallpaper)?'':' checked="checked"').' onclick="setWallpaper();setPosition(\'no\')"><span style="cursor:default" onclick="dgi(\'noUse\').checked=true;setWallpaper();setPosition(\'no\')">'.cfCaption('configWPNo').'</span><br/>';
echo '</div>';
// Send image
echo outDivFrame('frame2');
?>
<input type="radio" id="doUse" name="useWallpaper" value="yes"<?php echo ((!$wallpaper)?'':' checked="checked"'); ?> onclick=""><span style="cursor:default" onclick="dgi('doUse').checked=true"><?php echo cfCaption('configSelectWallpaper'); ?></span>
<br/>
<br/>
<?php // Image upload control ?>
<form name="wallpaperUploadForm" method="POST" enctype="multipart/form-data" style="margin:0;padding:0">
<input onchange="uploadWallpaper()" type="file" id="wallpaperUpload" name="wallpaperUpload" accept="image/gif,image/jpeg" size=7>
<div class="warning" id="wallpaperUploadWarning" style="visibility:hidden">
<?php echo outImageIcon('warning').cfCaption('explorerFormatError'); ?>
</div>
<div id="imagePositionControls" style="width:100%">
<div id="preview" style="background:url(/gfx/screenBg.jpg) no-repeat;position:relative;width:160px;height:100px;margin-right:10px;float:left;border:1px solid #AAA;overflow:hidden;text-align:center;white-space:nowrap"></div>
<?php //Position selection controls ?>
<input type="radio" onclick="setPosition(this.value)" id="pc" name="position" value="centered"<?php echo (($wallpaperPosition=='centered')?' checked="checked"':''); ?>><?php echo cfCaption('configWPCentered'); ?><br>
<input type="radio" onclick="setPosition(this.value)" id="pt" name="position" value="tiled"<?php echo (($wallpaperPosition=='tiled')?' checked="checked"':''); ?>><?php echo cfCaption('configWPTiled'); ?><br>
<input type="radio" onclick="setPosition(this.value)" id="ps" name="position" value="stretched"<?php echo (($wallpaperPosition=='stretched')?' checked="checked"':''); ?>><?php echo cfCaption('configWPStretched')?>
<br clear="all">
</div>
</form>
</div>
</div>
<?php
}
// Init themes list
$themes=cfMGetVar('weezoThemes');
foreach ($themes as $id=>$theme) if(@$theme['private']) unset($themes[$id]); else $themes[$id]['name']=cfUTF8Encode($id);
// $userFile: set theme level: user or general
if(isset($_POST['userFile'])) $userFile=$_POST['userFile'];
elseif(isset($_GET['userFile'])) $userFile=$_GET['userFile'];
else $userFile=false;
// General config
if(!$userFile || $userFile=='general'){
$userFile='general';
$wpTheme=cfGGetVar('theme');
$themeLevel='general';
}
// User config
elseif($user=WENV::userConfigs($userFile)){
$wpTheme=$user->getVar('theme');
if(!$wpTheme) $wpTheme='no';
$themeLevel='user';
$wallpaperPosition='';
}
else outDisplayErrorPage(cfCaption('configInvalidFile'));
/*
***************************************************************************************************************************
* Thumbnail image
***************************************************************************************************************************
*/
if(isset($_GET['previewThumbnail']) && count($_POST)==0) themeSelectionPreviewThumbnail();
/*
***************************************************************************************************************************
* Process POST commands
***************************************************************************************************************************
*/
themeSelectionProcessCommands();
/*
***************************************************************************************************************************
* HEAD, CSS & JS
***************************************************************************************************************************
*/
cfInsertHEAD(false);
echo '<meta width="'.(($themeLevel=='general')?'800x550':'675x420').'"></meta>';
echo '<meta icon="theme"></meta>';
echo '<meta title="'.cfCaption('genTheme').'"></meta>';
echo cfScriptLink('winClient.js');
?>
</head>
<body style="overflow:hidden">
<?php
require_once(INCLUDE_DIR.'outputFunctions.php');
/*
***************************************************************************************************************************
* Display themes thumbnails
***************************************************************************************************************************
*/
echo outDivFrame('frame1','',($themeLevel=='general')?'float:left;width:490px':'');
echo '<div class="frame1Header">'.outImageIcon('theme').cfCaption('genTheme').'</div>';
echo outDivFrame('frame2',false,'height:510px;overflow:auto');
/**
* If user-level or resource-level theme, add a "default theme" box
*/
if($themeLevel!='general') {
$themes=array('no'=>array('name'=>cfCaption('genDefault')))+$themes;
}
foreach ($themes as $key=>$theme) {
$o='';
// Default theme: replace preview by general-level theme's preview
if($key=='no' && isset($themes[cfGGetVar('theme')])){
$theme=@$themes[cfGGetVar('theme')];
$theme['name']=cfCaption('genDefault');
$theme['faded']=true;
}
// Preview thumbnail
if(file_exists(@$theme['dir'].'/thumbnail.png')) $o.='<img src="'.$theme['path'].'/thumbnail.png" style="width:125px;height:94px;'.((isset($theme['faded']))?outCssOpacity(50):'').'"><br>';
// No preview
else $o.='<img src="/gfx/screenBg.jpg" style="width:125px;height:94px"><br>';
$o.='<div style="position:absolute;bottom:15px;width:100%;text-align:center;font-size:150%" class="textShadow">'.ucfirst($theme['name']).'</div>';
echo str_replace('<','<',outBlockItem('themes',$o,'id="'.$key.'" ondblclick="selectTheme(\''.$key.'\',1)"','padding:9px',array('onclick'=>'selectTheme(\''.$key.'\')'),($wpTheme===$key)?'sel':'unsel')."\n");
}
echo '</div>';
echo '</div>';
/*
***************************************************************************************************************************
* Display login page selection control
** *************************************************************************************************************************
*/
if($themeLevel=='general') themeSelectionLoginTypeSelection();
/*
***************************************************************************************************************************
* Display wallpaper selection control
***************************************************************************************************************************
*/
// Retreive wallpaper src & position
list($wallpaper,$wallpaperPosition)=themeSelectionGetWallpaper();
if($themeLevel=='general') themeSelectionWallpaperSelection();
// Close button
if($themeLevel=='general'){
?>
<br><br><br><br><br><br>
<center>
<?php echo outBt(cfCaption('genClose'),outIcon('closeOK'),'javascript:wl.UICommand(\'close\')',false,false,false,'up',160); ?>
</center>
<?php
}
// Scripts
?>
<script type="text/javascript">
var userFile="<?php echo $userFile ?>";
function init(){
setWallpaper("<?php echo $wpTheme;?>","<?php if($wallpaper) echo $wallpaperPosition;?>");
}
function selectLoginType(lt,close){
wl.asr.send({'loginForm':lt,'close':(close)?1:0})
}
function selectTheme(t,close){
wl.asr.send({'setTheme':t,'userFile':userFile,'close':(close)?1:0})
}
function uploadWallpaper(){
var i=dgi('wallpaperUpload').value.toLowerCase();
if(i.substr(i.length-4)!='.gif' && i.substr(i.length-4)!='.jpg' && i.substr(i.length-5)!='.jpeg' && i.substr(i.length-4)!='.png')
dgi('wallpaperUploadWarning').style.visibility='';
else{
dgi('wallpaperUploadWarning').style.visibility='hidden';
D.wallpaperUploadForm.submit();
}
}
function setPosition(pos){
wl.asr.send({'setPosition':pos})
}
function setWallpaper(t,pos){
var c=dgi("preview"),i,e,l=['pc','pt','ps'];
if(!c) return;
var img='<img alt="" src="<?php echo $_SERVER['PHP_SELF'];?>?r='+Math.random()+'&theme='+t+'&previewThumbnail=1';
if(pos){
img+='&previewPos='+pos+'"';
switch(pos){
case 'stretched':
img=img+' style="width:100%;height:100%">';
break;
case 'centered':
c.style.textAlign='center'
img=img+' style="height:60px;margin-top:20px">';
break;
case 'tiled':
img+='>';
img=img+img+img+'<br>'+img+img+img;
c.style.textAlign='left'
break;
}
dgi('doUse').checked=true;
}
else{
img='';
dgi('noUse').checked=true;
}
setAlpha(dgi('imagePositionControls'),(pos)?1:0.5);
setAlpha(dgi('preview'),(pos)?1:0.5);
c.innerHTML=img;
for(i=1;i<l.length;i++) dgi(l[i]).disabled=(pos)?false:true;
}
init();
</script>